package ytdp.careagle.com.ytdp.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import ytdp.careagle.com.ytdp.R;
import ytdp.careagle.com.ytdp.entity.SeriesRelationship;

public class CarBrand2Adapter extends RecyclerView.Adapter<CarBrand2Adapter.ViewHolder> {
    protected Context mContext;
    protected List<SeriesRelationship.ChildrenBean> mDatas;
    protected LayoutInflater mInflater;
    private CarBrand2Adapter.OnitemClickListener onitemClickListener;

    public void setOnitemClickListener(CarBrand2Adapter.OnitemClickListener onitemClickListener) {
        this.onitemClickListener = onitemClickListener;
    }

    public interface OnitemClickListener {
        void itemClick(SeriesRelationship.ChildrenBean cityBean);
    }

    public CarBrand2Adapter(Context mContext, List<SeriesRelationship.ChildrenBean> mDatas) {
        this.mContext = mContext;
        this.mDatas = mDatas;
        mInflater = LayoutInflater.from(mContext);
    }

    public List<SeriesRelationship.ChildrenBean> getDatas() {
        return mDatas;
    }

    public CarBrand2Adapter setDatas(List<SeriesRelationship.ChildrenBean> datas) {
        mDatas = datas;
        return this;
    }

    @Override
    public CarBrand2Adapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(mInflater.inflate(R.layout.item_ser_cartype, parent, false));
    }

    @Override
    public void onBindViewHolder(final CarBrand2Adapter.ViewHolder holder, final int position) {
        final SeriesRelationship.ChildrenBean childrenBean = mDatas.get(position);
        holder.tvCity.setText(childrenBean.getName());
        holder.content.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onitemClickListener != null) {
                    onitemClickListener.itemClick(childrenBean);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDatas != null ? mDatas.size() : 0;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvCity;
        View content;

        public ViewHolder(View itemView) {
            super(itemView);
            tvCity = (TextView) itemView.findViewById(R.id.tvCity);
            content = itemView.findViewById(R.id.content);
        }
    }
}
